const WXAPI = require('apifm-wxapi')
Page({
  data: {
    footer_img: wx.getStorageSync('footer_img'),
    sphid: wx.getStorageSync('sphid'),
    index_video1: wx.getStorageSync('index_video1'),
    index_img1: wx.getStorageSync('index_img1'),
    index_img2: wx.getStorageSync('index_img2'),
    index_img3: wx.getStorageSync('index_img3'),
    defaultBanners: [],
    category: [],
    list: [],
    id:"418831",
    shuju:"",
    categories:[],
    categoriesDetal:"",
    categoriesDetal_img:"",
  },
  onLoad: function (options) {
   
    const that = this;
    that.setData({
      footer_img: wx.getStorageSync('footer_img'),
      sphid: wx.getStorageSync('sphid'),
      index_video1: wx.getStorageSync('index_video1'),
      index_img1: wx.getStorageSync('index_img1'),
      index_img2: wx.getStorageSync('index_img2'),
      index_img3: wx.getStorageSync('index_img3'),
    });
    that.getCategoryDetail(that.data.id);
    that.getlist(that.data.id);
  },



 
  onShow: function () {

  },

  


 


 async getCategoryDetail(e) {
  var that = this;
  await WXAPI.goodsCategoryDetail(that.data.id).then(function (res) {
    if (res.code == 0) {
      that.setData({
        categoriesDetal: res.data
      });
      
        that.setData({
          categoriesDetal_img:res.data.info.icon
        })

      console.log("categoriesDetal",that.data.categoriesDetal);
    }
  })
},


  // 获取最新作品
  // priceUp 价格升序，priceDown 价格倒序，ordersUp 销量升序，ordersDown 销量降序, sellsDown 商品销售数量降序排，addedUp 发布时间升序，addedDown 发布时间倒序, nameUp 商品名称升序, useful 点赞最多， dateEndAsc 即将结束的最考前；dateEndDesc 停售时间最大的越靠前; storesAsc 库存升序； storesDesc 库存倒序; goodReputation 好评多, views 浏览量
  async getlist(e) {
    var that = this;
    await WXAPI.goods({
      categoryId:e,
      page: 1,
      pageSize: 200,
      // orderBy: 'addedDown',
    }).then(function (res) {
      if (res.code == 0) {
        that.setData({
          list: res.data
        });
      }else{
        that.setData({
          list: []
        });
      }
      console.log("list",that.data.list);
    })
  },


    //跳转到详情页面
    toPost: function (t) {
      var a = t.currentTarget.dataset.postid;
      wx.navigateTo({
        url: "/pages/a1_video_post/index?id=" + a
      })
    },

  //跳转到列表页面
  toList: function (t) {
    var a = t.currentTarget.dataset.categoryid;
    wx.navigateTo({
      url: "/pages/a1_list/index?categoryId=" + a
    })
  },


  //跳转到a2页面
  toA2: function () {
    wx.switchTab({
      url: '/pages/a2/index',
    });
  },



  // 点击幻灯片
  gotoBannerLink: function (t) {
    var a = t.currentTarget.dataset.link;
    console.info("open link", a), a && (a.includes("https://mp.weixin.qq.com")) && wx.navigateTo({
      url: "/pages/webview/webview?link=" + a
    });
  },

  //拨打电话
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: wx.getStorageSync('phone')
    })
  },

  // 打开视频号主页
  toVideo() {
    wx.openChannelsUserProfile({
      finderUserName: wx.getStorageSync('sphid'),
    });
  },


  onShareAppMessage() { },
  onShareTimeline() { },
})